package com.bharat.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;

import com.bharat.domain.Patient;

public class PatientDaoImpl implements IPatientDao {

	private final Logger log = Logger.getLogger(PatientDaoImpl.class); 
	
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	// constructor
	public PatientDaoImpl() {
	}

	@Override
	public int createPatient(Patient patient) {
		log.info("creating new patient : "+ patient.getFirstName());
		int status = 0; 
		this.sessionFactory.getCurrentSession().save(patient);
		return status;
	}

	@Override
	public int updatePatient(Patient patient) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deletePatient(Patient patient) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Patient getPatientById(Long patientId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Patient> getPatientsByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Patient> getAllPatients() {
		List<Patient> patients = new ArrayList<Patient>();
		patients = this.sessionFactory.openSession().createCriteria(Patient.class).list();
		return patients;
	}

}
